import request from "./index.js"

// const HOST = 'https://it.jushi.com'

const HOST = 'http://dev.jushi.com'

export function getbaseURL() {
	console.log('1111111111', HOST)
	return HOST
}

export function showImage(url) {

	return HOST + '/api/file/view/' + url 
}

export const upLoadImage = (filePath, imgList) => {
	uni.showLoading({
		title: '上传中',
		mask: true
	});
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: HOST + "/api/file/upload",
      filePath: filePath,
      name: 'file',
      success: (uploadFileRes) => {
        let obj = JSON.parse(uploadFileRes.data);
        imgList.push(obj.data);
        console.log("imgList--------", imgList);
        
        if (obj.success) {
          resolve(imgList); // 成功后返回 imgList
          uni.showToast({
            title: '上传成功',
            duration: 1000
          });
        } else {
          reject(new Error('上传失败')); // 失败时抛出错误
          uni.showToast({
            title: '上传失败',
            duration: 1000
          });
        }
		uni.hideLoading()
      },
      fail: (err) => {
        reject(new Error(err.errMsg)); // 失败时抛出错误
        console.log('error', err.errMsg);
      }
    });
  });
};